"use strict"

/**
 * 补助标准新增、修改
 * sy
 * @param id
 */
function subsidyStandardFrom(id) {
    var title = "补助标准"
    if(id!=""){
        title = "修改"+title;
    }else{
        title = "新增"+title;
    }
    layer.open({
        type : 2,
        fix : true,
        skin : 'self-def', /* 自定义按钮样式 */
        anim : '5', /* 动画效果 */
//        move : [ '.layui-layer-title', true ],
        title : [ title, 'font-size:20px;font-weight:bold;'],
        offset : [ '30px' ],
        area : [ '60%', '70%' ],
        maxmin : false,
        closeBtn : 1,
        content:  path + '/bus/subsidyStandard/form?id='+id,
        btn : ['取消','保存'], /* 自定义按钮事件 */
        btn1 : function(index, layero) {
            layer.close(index);
        },
        btn2 : function(index, layero) {
            var innerObj = window[layero.find('iframe')[0]['name']];
            innerObj.$("#inputForm").submit();
            return false;
        }
    });
}

/**
 * 动物种类和疫苗品种二级联动
 * sy
 */
function animalTypeChange(){
    var animalTypeCode = $("#animalTypeCode").val();
    var vaccineTypeCode = $("#vaccineTypeCode").val();
    $.ajax({
        url : path + "/bus/vaccineManage/findVaccineTypeListByAnimalTypeCode",
        type : "post",
        data : { "animalTypeCode": animalTypeCode},
        async : false,
        success : function(data) {
            $("#vaccineTypeCode").empty();
            var data2 = eval(data);
            for(var i in data2) {
                var $option= $("<option >").attr({ "value" : data2[i].value}).text(data2[i].label);
                $("#vaccineTypeCode").append($option);
            }
        },
        error : function(e) {
        }
    });
    $("#vaccineTypeCode").select2("data", null);        //只清除option清不干净，所以做此处理
    $("#vaccineTypeCode").val(vaccineTypeCode).trigger("change");

}

/**
 * 疫苗品种和疫苗二级联动
 * sy
 */
function vaccineTypeChange(){
    var vaccineTypeCode = $("#vaccineTypeCode").val();
    var vaccineManageId = $("#vaccineManageId").val();
    $.ajax({
        url : path + "/bus/vaccineManage/findListByVaccineTypeCode",
        type : "post",
        data : { "vaccineTypeCode": vaccineTypeCode},
        async : false,
        success : function(data) {
            $("#vaccineManageId").empty();
            var data2 = eval(data);
            for(var i in data2) {
                var $option= $("<option >").attr({ "value" : data2[i].id}).text(data2[i].name);
                $("#vaccineManageId").append($option);
            }
        },
        error : function(e) {
        }
    });
    $("#vaccineManageId").select2("data", null);        //只清除option清不干净，所以做此处理
    $("#vaccineManageId").val(vaccineManageId).trigger("change");

}

/**
 * 疫苗厂家改变时，判断该厂家是否已经选过此疫苗
 * sy
 */
function changeEnt() {
    $.ajax({
        url : path + "/bus/subsidyStandard/changeEnt",
        type : "post",
        data : $("#inputForm").serialize(),
        async : false,
        success : function(data) {
            if(data =="error"){
                errorFlag2 = "1"
                top.$.jBox.tip("该厂家已经选过此疫苗！", "info");
            }else{
                errorFlag2 = '0';
            }
        },
        error : function(e) {
        }
    });
}